<?php
/**
 * Created by DRCOM.
 * User: GZX
 * Datetime: 2021-08-23 9:13
 */

namespace app\api\controller;
use fq\request\LoadRequest;
use think\Db;

class Test
{
    public function index(){
        echo get_activity_info();
        exit;
        $url = "http://v2.api.haodanku.com/item_detail?apikey=sylar&itemid=619736737189";
        $contents = file_get_contents($url);
        trace($contents,'error');
        $item = json_decode($contents, true);
        db('itemDetail')->strict(true)->insert($item['data'], true);
        dump( $item['data']);

        exit;
        $item = item_detail(640322415617);
        $content = json_decode($item,true);
        $aa = ($content['data']);
        $file = ROOT_PATH.'public/hdk/get_index_activity_items.json';
        $content = json_decode(file_get_contents($file),true);
        $bb = $content['data']['block'][0];
        unset($content['data']['block'][3]);
        $content['data']['block'][3] = $bb;
        $content['data']['block'][0]['item'][0] = $aa;

//        ($content['data']['block'][3]);
        echo json_encode($content);

//

    }

    public function pub(){
        $resul = get_relation_oauth_tpwd();
        dump($resul);
    }

    /**
     * tsayisi.com
    1143597681@qq.com
    frank13702743707
     */
    public function getorder()
    {
        $url = 'https://{API_KEY}:{PASSWORD}@{SHOP_NAME}.myshopify.com/admin/api/2021-01/orders.json';
        $list = file_get_contents($url);
        $list = json_decode($list);
        dump($list);

    }

    public function fseport(){
        $url = 'http://cbec.fsecb.com/api/fseport/user/notLogin/getTokenMessage';
        $time = time();
        $data = [
          'orgId'=>'900000038277',
          'messageKey'=>'20722295',
          'time'=>$time,
        ];
        $params = http_build_query($data);
        $data['mac'] = strtoupper(md5($params));
//        dump($data);

        $result = file_post_contents($url,$data);
        echo($result);
    }

    public function get_publisher_info(){
        $data = get_publisher_info();
        foreach ($data as $info){
            db('publisherInfo')->insert($info);
        }
    }


    public function wechat(){

        $itemId = 652597001851;
        dump($itemId);
        $itemDetail = item_detail($itemId);
        dump($itemDetail);
        $tpwd = get_tpwd($itemId);
        dump($tpwd);
        $contents = "6/:sun{$itemDetail['itemtitle']}
————
★【原价】{$itemDetail['itemtitle']}圆
★【有券】{$itemDetail['couponmoney']}圆
★【收益】{$itemDetail['tkmoney']}圆[Packet]
︾︾︾︾︾︾
/:heart復制这条信息，返回tao宝下箪{$tpwd}";
//        $itemId = 542839065907;
//        $rateurl = get_tpwd($itemId);
//        $itemInfo = json_decode($rateurl,true);
//        dump($itemInfo);
//        dump(item_detail($itemId));
    }

    public function jd(){
        $id = '-迪士尼母婴 母婴睡 跳跳虎70cm
页面多单有礼进去
下过二单的可领199-40母婴奍，拍2件
https://u.jd.com/nL9pa9h  
凑1件
https://u.jd.com/nL9rp9d  
叠加299-30奍，50.2亓';
//        $id = urlencode($id);
//        $res = get_jditems_link($id);
//        dump($res);
        $res = jd_url($id);
        dump($res);
    }

    public function ele(){
        $a = get_activity_info();
        dump($a);
    }

    public function dianying(){
        $c = cinema('13719205474','13719205474','13719205474');
        dump($c);
    }

    public function o2o(){
        $orders = db('orderDetails')->order('tb_paid_time desc')->limit(10)->select();
        foreach ($orders as $order){
            $data = [
                'order_no'=>$order['trade_id'],//订单号
                'total_price'=>$order['alipay_total_price'],//商品总金额(不含优惠折扣)
                'order_price'=>$order['alipay_total_price'],
                'pay_price'=>$order['alipay_total_price'],//
                'update_price'=>$order['alipay_total_price'],//
                'pay_status'=>20,//
                'pay_time'=>$order['tk_paid_time'],//
                'order_status'=>$order['tk_status'],//已付款：指订单已付款，但还未确认收货 已收货：指订单已确认收货，但商家佣金未支付 已结算：指订单已确认收货，且商家佣金已支付成功 已失效：指订单关闭/订单佣金小于0.01元，订单关闭主要有：1）买家超时未付款； 2）买家付款前，买家/卖家取消了订单；3）订单付款后发起售中退款成功；3：订单结算，12：订单付款， 13：订单失效，14：订单成功
                'create_time'=>strtotime($order['modified_time']),//
                'update_time'=>strtotime($order['modified_time']),//
                'user_id'=>1,
                'store_id'=>1001,
                'item_img'=>$order['item_img'].'_70x70.jpg',
                'item_title'=>$order['item_title'],
                'platform'=>'MP-WEIXIN',

            ];
            dump($data);
            db('xyshopOrder')->insert($data,true);
        }
    }

    public function tlj(){
        //淘礼金创建
        $itemId = 'd3tpU3Q6OxPyXs29JFet3-3zzX36MT0kpQmkBQhO';
//        $ii = create_taolijin($itemId);
//        halt($ii);

        $data = [
//            'appKey' => "5d9afc56d2ab8",
//            'version' => "v1.0.0",
            'alimamaAppKey'=>'32823552',
            'alimamaAppSecret'=>'c68903937449446f4c892a05f3892765',
            'name'=>'淘礼金来了',
            'itemId'=>$itemId,
            'pid'=>'111186000312',
            'perFace'=>1,
            'totalNum'=>1,
            'winNumLimit'=>1,
            'sendStartTime'=>date('Y-m-d H:i:s'),
            'sendEndTime'=>date('Y-m-d 23:59:59'),
            'useEndTimeMode'=>'2',
            'useStartTime'=>date('Y-m-d H:i:s'),
            'useEndTime'=>date('Y-m-d 23:59:59'),
//            'useThreshold'=>'2',
        ];
//        dump($data);
        $host = "https://openapi.dataoke.com/api/dels/taobao/kit/create-tlj";
        $version = 'v1.0.0';
        $result = dtk_request($host, $version, $data);
        halt($result);

        $url = $host . '?' . http_build_query($data);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $output = curl_exec($ch);
        $a = curl_error($ch);
//        if(!empty($a)){
//            return json_encode(array('code'=>10003, 'msg'=>$a));
//        }
        curl_close($ch);
        echo($output);
    }

    public function aabb()
    {
        $content = 'https://m.tb.cn/h.UepIgVI?tk=a5np2AaLuGN CZ0001 ';
        $data = [
            'apkey'       => '6a9ffd88-17a3-9f54-0bb7-b91a81405862',
            'tbname'      => 'tb370655212',
            'pid'         => 'mm_1520060136_2232550319_111183800425',//常规
            'content'     => $content,
            'tpwd'        => 1,
            'hasiteminfo' => 1,
        ];

        $url = "http://api.web.ecapi.cn/taoke/doItemHighCommissionPromotionLinkByAll?";

        $params = http_build_query($data);
        $result = file_get_contents($url . $params);
        $content = json_decode($result, true);
        dump($content, 'error');

    }

    public function parse(){
        $params = [
            'content' => "https://detail.tmall.com/item.htm?id=848696466080&skuId=5804177070188",
        ];
        $host = "https://openapi.dataoke.com/api/dels/kit/contentParse";

        $version = 'v1.0.0';
//        $params['type'] = 1;
//        $params['startTime'] = $startTime;
//        $params['endTime'] = $endTime;
//        $params['pageSize'] = 100;
//        $params['key'] = 'dfb1d213da0d7d78d6e94fe85d45585096c521f2492a845c903007a3e069d0a4185983bed66a34d9';


        $result = dtk_request($host, $version, $params);
        echo $result;
        exit;
        $result = json_decode($result, true);
//        $ch = curl_init();
//        curl_setopt($ch, CURLOPT_URL, $url);
//        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
//        curl_setopt($ch, CURLOPT_HEADER, 0);
//        $output = curl_exec($ch);
//        $a = curl_error($ch);
//        curl_close($ch);
//        echo $output;
//
//
//        $item = json_decode($output,true);
//        if (isset($item['data']['itemId'])){
//            $data = [
//                'appKey' => "5d9afc56d2ab8",
//                'version' => "v1.3.1",
//                'goodsId' => $item['data']['itemId'],
//            ];
//            $host = "https://openapi.dataoke.com/api/tb-service/get-privilege-link";
//            $url = $host . '?' . http_build_query($data);
//            $ch = curl_init();
//            curl_setopt($ch, CURLOPT_URL, $url);
//            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//            curl_setopt($ch, CURLOPT_TIMEOUT, 30);
//            curl_setopt($ch, CURLOPT_HEADER, 0);
//            $output = curl_exec($ch);
//            $a = curl_error($ch);
//            curl_close($ch);
//            $item = json_decode($output,true);
//            echo $item['data']['longTpwd'];
//
//        }

    }

    public function change(){
        $data = [
            'appKey' => "5d9afc56d2ab8",
            'version' => "v1.3.1",
            'goodsId' => 'NJr3eY4QMdt5tKX0xgixJJi0uB-mPkBXe3U73P9wgVdF9',
        ];
        $host = "https://openapi.dataoke.com/api/tb-service/get-privilege-link";
        $url = $host . '?' . http_build_query($data);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $output = curl_exec($ch);
        $a = curl_error($ch);
        curl_close($ch);
        echo $output;

    }

    public function detail(){
        $data = [
            'appKey' => "5d9afc56d2ab8",
            'version' => " v1.2.3",
            'goodsId' => 'NJr3eY4QMdt5tKX0xgixJJi0uB-mPkBXe3U73P9wgVdF9',
        ];
        $host = "https://openapi.dataoke.com/api/goods/get-goods-details";
        $url = $host . '?' . http_build_query($data);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $output = curl_exec($ch);
        $a = curl_error($ch);
        curl_close($ch);
        echo $output;

    }

    function oo()
    {
        $content = '【淘宝】https://m.tb.cn/h.537wIeq?tk=VoI4dCUuBMg CZ0001 「~德国拜耳拜灭士灭蚊驱蚊喷雾蚊香液驱蚊液强力驱蚊水室内防蚊杀蚊(~@ ~)」
点击链接直接打开 或者 淘宝搜索直接打开';
        $relationid = 2900106203;
        $remark = '';
//    使用剪切板识别
        $content = hdk_parse($content);
        halt($content);
        if (!$content) return false;
        trace('hdk:'.$content,'error');
        $data = [
            'apkey'       => '6a9ffd88-17a3-9f54-0bb7-b91a81405862',
            'tbname'      => 'tb05159005487',
            'pid'         => 'mm_3307787517_2726950248_114493300225',//常规
            'content'     => $content,
            'tpwd'        => 1,
            'hasiteminfo' => 1,
        ];
        //渠道id

            $data['relationid'] = $relationid;



        $url = "http://api.web.ecapi.cn/taoke/doItemHighCommissionPromotionLinkByAll?";
        trace('url:'.$url, 'error');
        trace($data, 'error');
        $params = http_build_query($data);
        $result = file_get_contents($url . $params);
        echo $result;
    }

    public function orders()
    {
        $orders1 = [];
        $host = 'https://openapi.dataoke.com/api/tb-service/get-order-details';
        $version = 'v1.0.0';
        $params['queryType'] = 1;
        $params['startTime'] = date('Y-m-d H:i:s',strtotime('-1 hour'));
        $params['endTime'] = date('Y-m-d H:i:s');
        $params['pageSize'] = 100;

        //常规订单
        $params['orderScene'] = 1;


        $result = dtk_request($host, $version, $params);

        echo $result;
    }

    public function itemlist(){
        $url = 'http://v2.api.haodanku.com/itemlist?apikey=sylar&nav=3&cid=0&back=100&min_id=1&sort=5';
        $content = file_get_contents($url);
        return $content;
    }

    public function ljf(){
        $content = '【淘宝】https://m.tb.cn/h.537wIeq?tk=VoI4dCUuBMg CZ0001 「~德国拜耳拜灭士灭蚊驱蚊喷雾蚊香液驱蚊液强力驱蚊水室内防蚊杀蚊(~@ ~)」
点击链接直接打开 或者 淘宝搜索直接打开';
        $data = [
            'appKey' => "5d9afc56d2ab8",
            'version' => "v1.0.0",
            'content' => $content,
            'tbAuthId' => 609772,
            'TbPid' => 'mm_1520060136_2232550319_111187350018',
        ];
        $host = "https://openapi.dataoke.com/api/dels/kit/contentParse";
        $url = $host . '?' . http_build_query($data);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $output = curl_exec($ch);
        $a = curl_error($ch);
        curl_close($ch);
//                    return $output;
        $item = json_decode($output, true);
        dump($item);
    }

    public function dtk(){
        $content = '【淘宝】https://m.tb.cn/h.537wIeq?tk=VoI4dCUuBMg CZ0001 「~德国拜耳拜灭士灭蚊驱蚊喷雾蚊香液驱蚊液强力驱蚊水室内防蚊杀蚊(~@ ~)」
点击链接直接打开 或者 淘宝搜索直接打开';
        $orders1 = [];
        $host = 'https://openapi.dataoke.com/api/dels/kit/contentParse';
        $version = 'v1.0.0';
        $params['content'] = $content;
        $result = dtk_request($host, $version, $params);
        echo $result;
    }

    //剪切板识别商品链接
public function dtk2(){
    $content = '【淘宝】https://m.tb.cn/h.537wIeq?tk=VoI4dCUuBMg CZ0001 「~德国拜耳拜灭士灭蚊驱蚊喷雾蚊香液驱蚊液强力驱蚊水室内防蚊杀蚊(~@ ~)」
点击链接直接打开 或者 淘宝搜索直接打开';
        $data = [
            'appKey' => "5d9afc56d2ab8",
            'version' => "v1.0.0",
            'content' => $content,
            'TbPid'=>'mm_1520060136_2232550319_111187350018',
            'tbAuthId'=>'609772',
        ];
        $host = "https://openapi.dataoke.com/api/dels/kit/contentParse";
        $url = $host . '?' . http_build_query($data);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        $output = curl_exec($ch);
        $a = curl_error($ch);
        curl_close($ch);
        echo $output;
    }

    public function copy(){
        $activeId = config('site.activity');
        $relationId = 2794015487;
        $tpwd = get_activity_info($activeId,$relationId);
        echo $tpwd;


    }

    public function banner(){
        $file = ROOT_PATH . '/application/banner.json';
        $content =  file_get_contents($file);
        $json = json_decode($content, true);
        foreach($json['remark']['building'] as $k=>$v){
            Db::table('tbl_khhy_building')->insert([
                'id'=>$k,
                'mobile'=>$v
            ]);
        }
    }

    public function hdkp()
    {
        $content = "【淘宝】极速退款 http://e.tb.cn/h.TXOxcBAWIME8wTm?tk=uDgM3tNTtbb HU7632 「立白天然茶籽洗洁精除菌去油洁净不伤手果蔬食品用家用实惠装厨房」
点击链接直接打开 或者 淘宝搜索直接打开";
        $result = hdk_parse($content);
        echo json_encode($result);

    }

    public function dtkp()
    {
        $params = [
            'content' => "【淘宝】极速退款 http://e.tb.cn/h.TXOxcBAWIME8wTm?tk=uDgM3tNTtbb HU7632 「立白天然茶籽洗洁精除菌去油洁净不伤手果蔬食品用家用实惠装厨房」
点击链接直接打开 或者 淘宝搜索直接打开",
        ];
        $host = "https://openapi.dataoke.com/api/dels/kit/contentParse";

        $version = 'v1.0.0';

        $result = dtk_request($host, $version, $params);
        echo $result;

    }

    public function dtkp2()
    {
        $params = [
            'content' => "【淘宝】极速退款 http://e.tb.cn/h.TXOxcBAWIME8wTm?tk=uDgM3tNTtbb HU7632 「立白天然茶籽洗洁精除菌去油洁净不伤手果蔬食品用家用实惠装厨房」
点击链接直接打开 或者 淘宝搜索直接打开",
        ];
        $host = "https://openapi.dataoke.com/api/tb-service/parse-content";

        $version = 'v1.0.0';

        $result = dtk_request($host, $version, $params);
        echo $result;

    }

    public function waljf(){
        $item_id = '843505822095';
        $result = $this->get_tpwd($item_id);
        print_r($result);
        echo $result;
        echo json_encode(get_tlj($item_id),256) ;
    }

    public function tlj2(){
        $itemId = 'https://uland.taobao.com/item/edetail?id=843505822095';
        echo $itemId;
        echo json_encode(get_tlj($itemId),256) ;


    }

    function get_tpwd($itemid, $relationId = '')
    {
        $url = 'http://v3.api.haodanku.com/ratesurl';
        $data = [
            'apikey'      => 'sylar',
            'tb_name'     => 'tb370655212',
            'itemid'      => $itemid,
            'pid'         => 'mm_1520060136_2232550319_111431400345',
            'get_taoword' => 1,
            //        'me'=>1,
            'title'       => '淘宝的商品'
        ];
        //是否渠道id
        if ($relationId) {
            $data['relation_id'] = $relationId;
        }
        trace('get_tpwd','error');
        trace($data,'error');
        file_put_contents('/tmp/xxy','error');
        $contents = file_post_contents($url, $data);
        echo $contents;
        exit;
        file_put_contents('/tmp/xxy',$contents);
        $contents = json_decode($contents, true);
        if (isset($contents['data']['taoword'])) {
            return $contents['data']['taoword'];
        }

    }

    public function myqp()
    {

        $content = '【淘宝】极速退款 http://e.tb.cn/h.TXOxcBAWIME8wTm?tk=uDgM3tNTtbb HU7632 「立白天然茶籽洗洁精除菌去油洁净不伤手果蔬食品用家用实惠装厨房」
点击链接直接打开 或者 淘宝搜索直接打开';
        $data = [
            'apkey'       => '6a9ffd88-17a3-9f54-0bb7-b91a81405862',
            'tbname'      => 'tb370655212',
            'pid'         => 'mm_1520060136_2232550319_111183800425',//常规
            'content'     => $content,
            'tpwd'        => 1,
            'hasiteminfo' => 1,
        ];
        //渠道id

        $url = "http://api.web.ecapi.cn/taoke/doItemHighCommissionPromotionLinkByAll?";
        trace('url:'.$url, 'error');
        trace($data, 'error');
        $params = http_build_query($data);
        $result = file_get_contents($url . $params);
        echo $result;
    }

    public function taoword(){
        $cookie = config('site.hdk_cookie');
        $userAgent = config('site.hdk_agent');
        $url = config('site.hdk_url');
        $referer = config('site.hdk_referer');
        $data = [
            'taoword' => 'https://3.cn/2-9iXxfc ',
            'request_head' => 'https',
            'analysis_taoword_type'=>1,
            'content_type'=>0,
//            'is_tlj'=>1,
        ];
        $options = [
            'http' => [
                'header'  => "Content-type: application/x-www-form-urlencoded\r\n" .
                "Cookie: $cookie\r\n".
                "User-Agent: $userAgent\r\n".
                "Referer: $referer",
                'method'  => 'POST',
                'content' => http_build_query($data),
            ],
        ];
        $context  = stream_context_create($options);
        $result = file_get_contents($url, false, $context);
        echo $result;
    }

    public function jd2(){
        $message = '京东】https://3.cn/2-9iXxfc「围裙防水防油可擦手」';
        $jdInfo = hdk_jd($message);
        echo($jdInfo);
    }

    public function jd_detail()
    {
        $text = <<<TEXT
【京东】https://3.cn/29ohp-sS「【补贴价￥34.8，已补￥35.1】金龙鱼乳玉皇妃稻香贡米2.5KG*2」
点击链接直接打开
TEXT;

        $begin = strpos($text,'https://3.cn');
        $content = substr($text,$begin,21);

        $cookie = config('site.hdk_cookie');
        $userAgent = config('site.hdk_agent');
        $url = 'https://publish.haodanku.com/toolapi/TransitionDdate_jd';
        $referer = 'https://www.haodanku.com/';
        $data = [
            'content' => $content,
            'sid' => '',
            'pid'=>1,
            'content_type'=>'2020989427_4100569006_3004015769',
            'unionid'=>2020989427,
        ];
        $options = [
            'http' => [
                'header'  => "Content-type: application/x-www-form-urlencoded\r\n" .
                    "Cookie: $cookie\r\n".
                    "User-Agent: $userAgent\r\n".
                    "Referer: $referer",
                'method'  => 'POST',
                'content' => http_build_query($data),
            ],
        ];
        $context  = stream_context_create($options);
        $result = file_get_contents($url, false, $context);
        echo $result;

    }

}

